<template>
     <p>正在授权中</p>
</template>

<script>



export default {
  name: 'newcrp',
  data(){
    return{
      code:'',
    }
  },
  created() {
    this.getCode();
  },
  methods:{
    login(code){
      const userInfo = {
        code
      }
      console.log(userInfo)
      this.$store.dispatch("newCrpLogin",userInfo ).then(() => {
        this.$router.push({ path: this.redirect || "/" }).catch(()=>{});

      }).catch(() => {
        console.log(userInfo,"userInfouserInfo")
        this.$message.error("登录失败")
      });
    },
    getUrlParam(path, name) {
      var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
      if (reg.test(path)) {
        return unescape(RegExp.$2.replace(/\+/g, " "));
      }
      return "";
    },
    getCode() {
      this.code = this.getUrlParam(window.location.href, "code");
      if (this.code === null || this.code === "") {
        window.location.href ="http://auth.sdlivc.com/oauth2/authorize?client_id=zsk_app&response_type=code&scope=openid&redirect_uri=http://knowbase.sdlivc.com/newcrplogin";
      }
      this.login(this.code);
    },
  },
}
</script>

<style scoped>

</style>
